package com.example.dorm1_demo.service;

import com.example.dorm1_demo.entity.Student;
import com.example.dorm1_demo.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    @Autowired
    private StudentMapper studentMapper;

    // 获取所有学生信息
    public List<Student> getAllStudents() {
        return studentMapper.selectAll();
    }

    // 根据ID获取学生信息
    public Student getStudentById(Integer id) {
        return studentMapper.selectById(id);
    }
    // 根据姓名搜索学生信息
    public List<Student> searchStudentsByName(String name) {
        return studentMapper.selectByName(name);
    }

    // 添加新的学生信息
    public boolean addStudent(Student student) {
        return studentMapper.insert(student) > 0;
    }

    // 更新学生信息
    public boolean updateStudent(Student student) {
        return studentMapper.update(student) > 0;
    }

    // 删除学生信息
    public boolean deleteStudent(Integer id) {
        return studentMapper.delete(id) > 0;
    }

    // 根据宿舍ID获取学生列表
    public List<Student> getStudentsByDormitoryId(Integer dormitoryId) {
        return studentMapper.selectByDormitoryId(dormitoryId);
    }
}